//
//  HELSigninCell.m
//  HandheldELearn
//
//  Created by 陈武琦 on 16/9/22.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "HELSigninCell.h"
#import "NSString+Utilities.h"
#import "NSDate+Category.h"
@implementation HELSigninCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [[self.bgView layer] setShadowOffset:CGSizeMake(5, 5)];
    [[self.bgView layer] setShadowRadius:5];
    [[self.bgView layer] setShadowOpacity:1];
    [[self.bgView layer] setShadowColor:[UIColor darkGrayColor].CGColor];
}


- (void)setModel:(HELSigninCourseModel *)model {
    _model = model;
    
    self.week.text = [self setWeekWithtime:model.courseStart];
    
    self.title.text = model.courseName;
    self.classLocation.text = model.holdPlace;
    [self setTeacherNameText:model.teacher];
    self.registerDate.text = [NSString timeStringMMDDHMFrom:[model.courseStart longLongValue]];
    self.registerTime.text = [NSString timeStringMMDDHMFrom:[model.courseEnd longLongValue]];
    self.signInDate.text = [NSString timeStringMMDDHMFrom:[model.signStart longLongValue]];
    self.signInTime.text = [NSString timeStringMMDDHMFrom:[model.signEnd longLongValue]];
    if (![self.model.signType isEqualToString:@"yesSign"]) {
        self.haveSignedInImage.hidden = YES;
    }else {
        self.haveSignedInImage.hidden = NO;
    }

}

- (void)setTeacherNameText:(NSString *)name {

    if ([name isEmpty] || name == nil) {
        self.teacherIcon.hidden = YES;
        self.teacherLabel.hidden = YES;
        self.teacherName.hidden = YES;
        self.teacherHeight.constant = 0.0;
        self.teacherTop.constant = 0.0;
    }else {
        self.teacherIcon.hidden = NO;
        self.teacherLabel.hidden = NO;
        self.teacherName.hidden = NO;
        self.teacherHeight.constant = 18.0;
        self.teacherTop.constant = 12.0;
        self.teacherName.text = name;
    }
}


- (NSString *)setWeekWithtime:(NSString *) time {
    
    //当前的日期为UTC
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[time longLongValue]/1000];
    
    NSString *weekDay;
    
    switch ([date weekDescription]) {//此处得到星期是正常的
        case 1:
            weekDay = @"星期日";
            break;
        case 2:
            weekDay = @"星期一";
            break;
        case 3:
            weekDay = @"星期二";
            break;
        case 4:
            weekDay = @"星期三";
            break;
        case 5:
            weekDay = @"星期四";
            break;
        case 6:
            weekDay = @"星期五";
            break;
        case 7:
            weekDay = @"星期六";
            break;
            
        default:
            break;
    }
    return weekDay;
}

- (void)setColorIndex:(NSInteger)index {
    NSArray *colors = @[HexRGB(0xCC0000),HexRGB(0xFFCC00),HexRGB(0xFF99FF),HexRGB(0xFF99FF),HexRGB(0xFF0000),HexRGB(0xFF99FF),HexRGB(0x9900F)];
    [self setWeekColor:colors[index]];
}

- (void)setTeacherHidden:(BOOL)hidden {

    self.teacherIcon.hidden = hidden;
    self.teacherLabel.hidden = hidden;
    self.teacherName.hidden = hidden;
    if (hidden) {
        self.teacherHeight.constant = 0;
    }else {
        self.teacherHeight.constant = 15;
    }
}


- (void)setWeekColor:(UIColor *)color {
    self.bgColorView.backgroundColor = color;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
